<div class = "pt-table-wrap">
    <h4 class = "pt-msg-title">
        <b class = "f-fl">{$typename}管理</b>
        <span>
        <a href='{link=admin.category.add}' class = "btn btn-success btn-sm f-fr">添加顶级分类</a>
        </span>
    </h4>
    <div class = "pt-list">
        <div class = "pt-list-title">
            <p class = "f-fl tips">
                当前条件下共有<b class = "c-red"> {$totalnum} </b>个{$typename}
            </p>
            <div class = "bulk-actions f-fr">
                过滤条件
                <select class = "input-box" data = "status">
                    <option value = "">全部状态</option>
                    <option value = "1">正常</option>
                    <option value = "0">禁用</option>
                </select>&nbsp;&nbsp;
            </div>
        </div>
        <div class = "f-clear"></div>
        <form method = "post" action = "{link='admin.category.'}">
            <table class = "pt-list-table">
                <thead>
                <tr>
                    <th class = "f-tal">分类名称</th>
                    <!--th class = "f-tal" style="width: 100px">关键字</th-->
                    <th class = "f-tal" style="width: 100px">所用模型</th>
                    <th class = "f-tal" style="width: 50px">排序</th>
                    <th class = "w-word3">状态</th>
                    <th class = "operate w-operate4">操作</th>
                </tr>
                </thead>
                <tbody>
                {loop="list"}
                <tr class="cat{$loop.id}">
                    <td class = "f-tal">
						{if $loop.level>0}{$loop.level|str_repeat='　',@}┣━{/if}<span class = "icon icon-list" style = "font-size:16px;vertical-align: middle"></span>
                        <input type = "text" name="name[{$loop.id}]" value = "{$loop.name}" class = "input-text" style = "width:100px;margin-left: 5px" />

                    </td>
                    <!--td class = "f-tal">
                        <input type = "text" name="key[{$loop.id}]" value = "{$loop.key}" class = "input-text" style = "width:100px;" />
                    </td-->
                    <td class = "f-tal">
                        <select class = "input-box" name = "module[{$loop.id}]">
                            {section loop=$module item=$modulename}
                            {if $loop.module_id==$modulename.id}
                            <option value = "{$modulename.id}" selected>{$modulename.name}</option>
                            {else}
                            <option value = "{$modulename.id}">{$modulename.name}</option>
                            {/if}
                            {/section}
                        </select>
                    </td>
                    <td class = "f-tal">
                        <input type = "text" name="ordernum[{$loop.id}]" value = "{$loop.ordernum}" class = "input-text" style = "width:50px;text-align: right" />
                    </td>
                    <td>{$loop.status|default='<span class = "label label-warning">禁用</span>','<span class = "label label-success">正常</span>'}</td>
                    <td class = "operate">
                        <a href = "{link=admin.category.add pid=$loop.id}"><i class = "icon icon-plus"></i>子类</a>
                        <a href = "{link=admin.category.edit id=$loop.id}"><i class = "icon icon-edit"></i>编辑</a>
                        <a href = "javascript:;" class="del" data-id="{$loop.id}"><i class = "icon icon-trash"></i>删除</a>
                        <a href = "javascript:;" class="changestatus" data-id="{$loop.id}">
                            {$loop.status|default='<i class = "icon icon-ok-circle"></i>启用','<i class = "icon icon-ban-circle"></i>禁用'}
                        </a>
                    </td>
                </tr>
                {/loop}
                </tbody>
            </table>
            <div class = "pt-list-footer">
                <div class = "f-fl">
                    <input type = "submit" class = "btn btn-primary btn-sm" value = "批量修改">
                </div>
                <div class = "f-clear"></div>
            </div>
        </form>
    </div>
</div>
<script type = "text/javascript">
    $(function(){
        $('.changestatus').on('click',function(){
            var status,obj=$(this);
            if (obj.find('i').is('.icon-ok-circle')){
                status=1;
            }else{
                status=0;
            }
            $.post('{link=admin.category.changestatus}',{v:status,id:obj.data('id')},function(res){
                if (res.status==1){
                    if (status){
                        obj.html('<i class = "icon icon-ban-circle"></i>禁用').parent().prev().html('<span class = "label label-success">正常</span>');
                    }else{
                        obj.html('<i class = "icon icon-ok-circle"></i>启用').parent().prev().html('<span class = "label label-warning">禁用</span>');
                    }
                }else{
                    alert(res.info);
                }
            },'json');
        });
        $('.del').on('click',function(){
            var id=$(this).data('id');
            if (confirm('确认删除么？')){
                $.post('{link=admin.category.del}',{id:id},function(res){
                    if (res.status==1){
                        $('.cat'+id).hide(200).remove();
                    }else{
                        alert(res.info);
                    }
                },'json')
            }
        })
    });
</script>